<template>
  <div class="login-wrapper">
    <div class="custom-topHr"></div>

    <div class="logo-box">
      <img class="logo" src="@/assets/images/logo1.png">
    </div>
    <div class="login-box">
      <div class="submit-box">
        <button class="submit-btn" v-on:click="userlogin">用户登录</button>
        <button class="submit-btn" v-on:click="storelogin">门店登录</button>
        <button class="submit-btn" v-on:click="otherlogin">代理商登录</button>
        <button class="submit-btn" v-on:click="otherlogin">门店销售登录</button>
        <button class="submit-btn" v-on:click="otherlogin">销售经理登录</button>

        <p class="privacy-txt">
          <span>登录即代表已经并同意</span>
          <a @click="showdialog">《还美医疗整形隐私政策》</a>
        </p>
      </div>
    </div>
      <el-dialog title="还美医疗整形隐私政策" :visible.sync="dialogVisible">
            <div>
                {{this.content}}
            </div>
          <span slot="footer" class="dialog-footer">

                <el-button type="primary" @click="dialogVisible = false">同意</el-button>
            </span>
      </el-dialog>

  </div>
</template>

<script type="text/ecmascript-6">
import constant from "@/utils/constant.js";
// 引用API文件
import http from "@/utils/http.js";
export default {
  name: "login",
  data() {
    return {
      username: "",
      password: "",
        dialogVisible:false,
        title:"",
        content:""
    };
  },
  components: {},
  created() {
    let user_type = localStorage.getItem("user_type");
    let user_token = localStorage.getItem("user_token");

    if (user_token) {
      this.$router.push({
          path: '/center'
      });
    }
    this.getArticle()
  },
  methods: {
      getArticle(){
          http.post(this, {
              url: "article/detail",
              data: {
                  id:343,
              },
              dataType: "json",
              success: function(data) {
                  console.log("登录:", data);
                  if (data.status == 1) {
                        this.title = data.info.title
                      this.content = data.info.content
                  } else {
                      this.$message.error(data.info);
                  }
              }
          });
      },
      showdialog(){
            this.dialogVisible = true
      },
    userlogin() {
      //window.location.href = "/author/author";
      this.$router.push({
          path: '/author/author'
      });
    },
    otherlogin() {
        window.location.href = "/login/agentlogin";
    },
    storelogin(){
        window.location.href = "/login/storelogin";
    },
    login() {
      let username = this.username;
      let password = this.password;

      if (username == "" || password == "") {
        this.$message({
          message: "请填写用户名或密码",
          type: "warning"
        });
      } else {
        http.post(this, {
          url: "passport/login",
          data: {
            username: this.username,
            password: this.password
          },
          dataType: "json",
          success: function(data) {
            console.log("登录:", data);
            if (data.status == 1) {
              let user_info = data.info;
              localStorage.setItem("user_name", user_info.username);
              localStorage.setItem("user_token", user_info.token);
              this.$router.push({
                //核心语句
                path: "/center"
              });
            } else {
              this.$message.error(data.info);
            }
          }
        });
      }
    }
  }
};
</script>

<style scoped lang="scss">
.submit-box {
  margin-top: 0.2rem;
  .privacy-txt {
    margin-top: 0.2rem;
  }
}
.login-wrapper{
    /deep/.el-dialog{
        width:80%;
    }
}
</style>
